import { Store } from "./store";
import Cookie from "../utils/cache";
import { get, post } from '../utils/request'
import router from '../router/index'
class UserStore extends Store {
  constructor() {
    super()
    this.state.token = Cookie.get("authorization")
    this.state.user = Cookie.get("user") || {}
  }
  data() {
    return {
      token: "",
      user:{}
    };
  }
  async login(data) {
    let res = await post('v1/admin_user/login', data.form)
    if (res.data.token) {
      Cookie.set("authorization", res.data.token)
      Cookie.set("user", res.data.user)
      this.state.token = res.data.token
      this.state.user = res.data.user
      router.push("/")
    }
  }
  loginOut() {
    this.state.token = "";
    Cookie.set("authorization", "")
  }
}
export const userStore = new UserStore();
